#include "appui.h"
#include <QHBoxLayout>
#include <QVBoxLayout>


appui::appui(QWidget *parent) :
    QWidget(parent), m_sum(new Summator(this))
{

    m_sum->setA(0);
    m_sum->setB(0);

    QHBoxLayout *hlay = new QHBoxLayout();
    QHBoxLayout *hlay1 = new QHBoxLayout();
    QHBoxLayout *hlay2 = new QHBoxLayout();
    QVBoxLayout *vlay = new QVBoxLayout();

    hlay->addWidget(new QLabel("sum", this));
    labelSum = new QLabel("0", this);
    hlay ->addWidget(labelSum);
    vlay->addLayout(hlay);

    hlay1->addWidget(new QLabel("A", this));
    valueA = new QLineEdit("0", this);
    hlay1->addWidget(valueA);
    vlay->addLayout(hlay1);

    hlay2->addWidget(new QLabel("B", this));
    valueB = new QLineEdit("0", this);
    hlay2->addWidget(valueB);
    vlay->addLayout(hlay2);

    button = new QPushButton("SET", this);
    vlay->addWidget(button);

    setLayout(vlay);



    connect(button, SIGNAL(clicked()), this, SLOT(setValue()));
    connect(m_sum, SIGNAL(valueChanged()), this, SLOT(sumValue()));

}

void appui::setValue()
{
    m_sum->setA(valueA->text().toInt());
    m_sum->setB(valueB->text().toInt());
}

void appui:: sumValue()
{
    labelSum->setText("Sum = " + QString::number(m_sum->sum()));

}
